package com.healthcenter.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.apache.log4j.Logger;

import com.healthcenter.entity.Patient;
import com.healthcenter.persistence.dao.PatientDAO;
import com.healthcenter.persistence.dao.impl.PatientDAOImpl;
import com.healthcenter.persistence.dao.impl.PatientDAOTest;

@Path("/patient")
public class PatientService {
	
	private static final Logger LOGGER = Logger.getLogger(PatientService.class);

	@GET
	@Path("/{name}/{lastName}/{idCard}")
	public Response printMessage(@PathParam("name") String name,
			@PathParam("lastName") String lastName,
			@PathParam("idCard") String idCard) {

		String result = "Adding patient : " + name;
		PatientDAO patientDAO = new PatientDAOImpl();
		patientDAO.add(new Patient(name, lastName, idCard));

		return Response.status(200).entity(result).build();

	}

	@GET
	@Path("/add/{name}/{lastName}/{idCard}")
	@Produces("application/json")
	public Patient addPatient(@PathParam("name") String patientName,
			@PathParam("lastName") String lastName,
			@PathParam("idCard") String idCard) {

		Patient patient = new Patient(patientName, lastName, idCard);
		PatientDAO patientDAO = new PatientDAOImpl();
		patientDAO.add(patient);
		return patient;

	}

	@POST
	@Path("/add")
	@Consumes("application/json")
	public Response createProductInJSON(Patient patient) {
		LOGGER.info("adding post"+patient);
		String result = "patient created : " + patient;
		PatientDAO patientDAO = new PatientDAOImpl();
		patientDAO.add(patient);
		return Response.status(201).entity(result).build();

	}

}
